package dev.hxliu.cn.inject;

import org.springframework.core.ResolvableType;

import java.lang.reflect.Type;
import java.util.Objects;
import java.util.function.Function;
import java.util.function.UnaryOperator;

public interface InjectMethod<T> {
    T inject() throws Throwable;

    @SuppressWarnings( "unused")
    default Class<?> getSuperclassParameter() {
        ResolvableType resolvableType = ResolvableType.forClass(this.getClass());
        ResolvableType injectMethodType = resolvableType.as(InjectMethod.class);
        ResolvableType genericType = injectMethodType.getGeneric();
        Type type = genericType.getType();
        if(type instanceof Class) {
            return (Class<?>) type;
        }
        return Objects.class;
    }

    // 以整体对象传参注入
    public static interface InjectMethodArgObject<T,F> extends InjectMethod<Function<T,  F>> {
        @Override
        Function<T, F> inject();
    }

    // 以当前注解字段传参注入
    public static interface  InjectMethodArgColumn<T> extends InjectMethod<UnaryOperator< T>> {
        @Override
        UnaryOperator< T> inject();
    }
}
